package cn.kgc.itrip.biz.service.impl;

import cn.kgc.itrip.beans.common.ResponseCode;
import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.pojo.ItripUserLinkUser;
import cn.kgc.itrip.beans.model.vo.ItripAddUserLinkUserVo;
import cn.kgc.itrip.beans.model.vo.ItripModifyUserLinkUserVo;
import cn.kgc.itrip.biz.service.UserorderService;
import cn.kgc.itrip.mapper.itripUserLinkUser.ItripUserLinkUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 阿泽
 */
@Service("userorderService")
@Slf4j
public class UserorderServiceImpl implements UserorderService {
    @Resource
    ItripUserLinkUserMapper itripUserLinkUserMapper;

    /**
     * 新增常用联系人接口
     *
     * @param
     * @return
     */
    @Override
    public ServerResponse adduserlinkuser(ItripAddUserLinkUserVo itripAddUserLinkUserVo) {
        ItripUserLinkUser itripUserLinkUser = new ItripUserLinkUser();

        itripUserLinkUser.setLinkUserName(itripAddUserLinkUserVo.getLinkUserName());
        itripUserLinkUser.setLinkIdCard(itripAddUserLinkUserVo.getLinkIdCard());
        itripUserLinkUser.setLinkPhone(itripAddUserLinkUserVo.getLinkPhone());
        itripUserLinkUser.setUserId(itripAddUserLinkUserVo.getUserId());
        itripUserLinkUser.setLinkIdCardType(itripAddUserLinkUserVo.getLinkIdCardType());
        Integer integer = itripUserLinkUserMapper.insertItripUserLinkUsers(itripUserLinkUser);
        if (integer < 0) {
            return ServerResponse.createByErrorMessage("添加失败");
        }
        return ServerResponse.createBySuccess();
    }

    /**
     * 修改常用联系人信息
     */

    @Override
    public ServerResponse modifyuserlinkuser(ItripModifyUserLinkUserVo itripModifyUserLinkUserVO) {
        ItripUserLinkUser itripUserLinkUser = new ItripUserLinkUser();
        itripUserLinkUser.setLinkUserName(itripModifyUserLinkUserVO.getLinkUserName());
        itripUserLinkUser.setLinkIdCardType(itripModifyUserLinkUserVO.getLinkIdCardType());
        itripUserLinkUser.setUserId(itripModifyUserLinkUserVO.getUserId());
        itripUserLinkUser.setLinkPhone(itripModifyUserLinkUserVO.getLinkPhone());
        itripUserLinkUser.setId(Long.valueOf(itripModifyUserLinkUserVO.getId()));
        itripUserLinkUser.setLinkIdCard(itripModifyUserLinkUserVO.getLinkIdCard());
        Integer modifyuserlinkuser = itripUserLinkUserMapper.modifyuserlinkuser(itripUserLinkUser);
        if (modifyuserlinkuser < 0) {
            return ServerResponse.createByErrorMessage("修改失败");
        }
        return ServerResponse.createBySuccess("修改成功");
    }

    /**
     * 删除联系人
     * @param ids
     * @return
     */
    @Override
    public ServerResponse deluserlinkuser(Integer ids) {
        if (ids==null) {
            log.error("根据用户id删除联系人时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }

        try {
            Integer integer = itripUserLinkUserMapper.deleteItripUserLinkUserById(Long.valueOf(ids));
            if (integer<0){
                return ServerResponse.createByErrorMessage("删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ServerResponse.createBySuccess();
    }
}
